package com.huangwei.controller;

import com.huangwei.model.Car;
import com.huangwei.service.RecommendService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;

@RestController
@RequestMapping("/carList")
public class CarListController {
    @Resource
    RecommendService recommendService;

    @GetMapping("/getCars")
    public List<List<Car>> getCars(HttpServletRequest request) {
        int userId;
        HttpSession session = request.getSession();
        if (session.getAttribute("user") == null) {
            userId = -1;
        } else {
            userId = Integer.parseInt((String) session.getAttribute("user"));
        }
        return recommendService.getCarList(userId);
    }
}
